#include "usermenu.h"
#include "models/command.h"
#include "qdebug.h"
#include "touchbutton.h"
#include <QEvent>
#include <QApplication>
#include <QVBoxLayout>
#include <QPushButton>

UserMenu::UserMenu(QStringList lsBtns, QWidget *parent) :
    PopupDialog(parent, false)  // 不自动居中
{
    setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
    setupUI(lsBtns);
}

UserMenu::~UserMenu()
{
}

void UserMenu::setupUI(QStringList lsBtns)
{
    // 设置窗口样式
    setStyleSheet(
        QString(
        "QPushButton {"
        "    background-color: transparent;"
        "    color: white;"
        "    border: none;"
        "    text-align: center;"
        "    padding: 8px 16px;"
        "    font: %1px '微软雅黑';"
        "    min-width: %2px;"
        "}"
        "QPushButton:hover {"
        "    background-color: #3D3D3D;"
            "}").arg(int(20*g_xScale)).arg(int(120*g_xScale)));

    QVBoxLayout* layout = new QVBoxLayout(this);
    layout->setSpacing(0);
    layout->setContentsMargins(11, 20, 10, 30);

    for(int i = 0; i < lsBtns.count(); ++i)
    {
        TouchButton* btn = new TouchButton(lsBtns.at(i), this);
        btn->setProperty("index", i+1);  // 存储按钮索引
        connect(btn, &QPushButton::clicked, this,[=](){
            done(btn->property("index").toInt());
        });
        layout->addWidget(btn);
    }
}

